package com.swy.shopgroup.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.swy.shopgroup.CircleImageView;
import com.swy.shopgroup.R;
import com.swy.shopgroup.entity.Accepts;
import com.swy.shopgroup.entity.ShopGoIn;
import com.swy.shopgroup.network.NetAdress;

import java.util.ArrayList;
import java.util.List;

public class GoInAdapter extends BaseAdapter {

    private List<ShopGoIn.DataBean> list = new ArrayList<>();
    private LayoutInflater inflater;

    public GoInAdapter(Context context, List<ShopGoIn.DataBean> list) {
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_go_in, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(list.get(position).getName());
        viewHolder.info.setText(list.get(position).getShopinfo());
        Glide.with(viewHolder.icon.getContext()).load(NetAdress.upload + list.get(position).getIcon()).into(viewHolder.icon);
        Glide.with(viewHolder.codePage.getContext()).load(NetAdress.upload + list.get(position).getPagecode()).into(viewHolder.codePage);
        return convertView;
    }

    class ViewHolder {
        private TextView name, info;
        private CircleImageView icon;
        private ImageView codePage;

        public ViewHolder(View v) {
            name = v.findViewById(R.id.name);
            info = v.findViewById(R.id.info);
            icon = v.findViewById(R.id.icon);
            codePage = v.findViewById(R.id.codePage);
        }
    }
}
